﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StudyAddView.xaml.cs" company="ELEN 7045 GROUP II">>
//   Contributed by E.Vosloo
// </copyright>
// <summary>
//   Interaction logic for StudyAddView.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Presentation.Module.StudyDefinition.Views
{
    #region

    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;

    using Presentation.Module.StudyDefinition.Interfaces.ViewModels;
    using Presentation.Module.StudyDefinition.Interfaces.Views;
    using Presentation.Shell.Interfaces;

    #endregion

    /// <summary>
    /// Interaction logic for StudyAddView.xaml
    /// </summary>
    public partial class StudyAddView : UserControl, IStudyAddView
    {
        #region Constants and Fields

        /// <summary>
        /// The study add view instance.
        /// </summary>
        public IStudyAddViewModel studyAddViewInstance;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="StudyAddView"/> class.
        /// </summary>
        /// <param name="studyAddViewModel">
        /// The study add view model.
        /// </param>
        public StudyAddView(IStudyAddViewModel studyAddViewModel)
        {
            InitializeComponent();

            this.studyAddViewInstance = studyAddViewModel;
            this.studyAddViewInstance.Initialize();
            this.DataContext = this.studyAddViewInstance;
            this.studyAddViewInstance.View = this;
        }

        #endregion

        #region Events

        /// <summary>
        /// The view exit.
        /// </summary>
        public event ViewExit ViewExit;

        #endregion

        #region Methods

        /// <summary>
        /// The cancel.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void Cancel(object sender, RoutedEventArgs e)
        {
            if (this.ViewExit != null)
            {
                this.ViewExit.Invoke();
            }
        }

        /// <summary>
        /// The update controls.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void UpdateControls(object sender, RoutedEventArgs e)
        {
            BindingExpression bindExp = ((ItemsControl)e.OriginalSource).GetBindingExpression(ItemsControl.ItemsSourceProperty);
            
            bindExp.UpdateSource();
            bindExp.UpdateTarget();
            this.InvalidateVisual();
        }

        #endregion
    }
}
